/*
package com.ruoyi.framework.aspectj;



import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import com.qiniu.util.Auth;
import com.ruoyi.common.annotation.QiniuPrivateUrl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.MethodParameter;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;

import javax.annotation.PostConstruct;

@ControllerAdvice
public class QiniuUrlResponseAdvice implements ResponseBodyAdvice<Object> {

  //  @Value("${OSS.accessKey}")
    private String accessKey = "0E-e2UMa9nD1wHN8fGailcHECGe7HG72Bm-b-A62";

//    @Value("${OSS.secretKey}")
    private String accessSecretKey = "fLvYWB9lDrsTDommuUZsBrq9xAs4lFxLT-t6kV50";

  //  @Value("${OSS.bucketName}")
    private String bucket;

  //  @Value("${OSS.path}")
    private String DOMAIN = "http://cdn.jiubeimao.com";

    private Auth auth = Auth.create(accessKey, accessSecretKey);
    private long expireSeconds = 3600;

    @Override
    public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
        // 对所有返回值进行处理
        return true;
    }

    @Override
    public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType,
                                  Class<? extends HttpMessageConverter<?>> selectedConverterType,
                                  ServerHttpRequest request, ServerHttpResponse response) {
        if (body == null) {
            return null;
        }
        try {
            processObject(body);
        } catch (Exception e) {

        }
        return body;
    }

    private void processObject(Object obj) throws IllegalAccessException {
        if (obj == null) {
            return;
        }

        // 如果是集合类型,处理集合中的每个元素
        if (obj instanceof Collection) {
            for (Object item : (Collection<?>) obj) {
                processObject(item);
            }
            return;
        }

        // 处理对象中的字段
        Class<?> clazz = obj.getClass();
        for (Field field : clazz.getDeclaredFields()) {
            field.setAccessible(true);

            QiniuPrivateUrl annotation = field.getAnnotation(QiniuPrivateUrl.class);
            if (annotation != null) {
                Object fieldValue = field.get(obj);
                if (fieldValue instanceof String) {
                    String url = (String) fieldValue;
                    if (url != null && !url.isEmpty()) {
                        String processedUrl = processQiniuUrl(url, annotation.isRichText());
                        field.set(obj, processedUrl);
                    }
                }
            }

            // 递归处理复杂对象
            Object fieldValue = field.get(obj);
            if (fieldValue != null && !isBasicType(fieldValue.getClass())) {
                processObject(fieldValue);
            }
        }
    }

    private boolean isBasicType(Class<?> clazz) {
        return clazz.isPrimitive() ||
                clazz == String.class ||
                clazz == Integer.class ||
                clazz == Long.class ||
                clazz == Double.class ||
                clazz == Float.class ||
                clazz == Boolean.class ||
                clazz == Byte.class ||
                clazz == Character.class;
    }

    private String processQiniuUrl(String url, boolean isRichText) {
        if (isRichText) {
            // 处理富文本中的URL
            return processRichTextUrls(url);
        } else {
            // 处理单个URL
            return generatePrivateUrl(url);
        }
    }

    private String processRichTextUrls(String content) {
        // TODO: 实现富文本中URL的处理逻辑
        // 可以使用正则表达式匹配富文本中的URL并替换
        return replaceLinksWithPrivateUrls(content);
    }

    public String replaceLinksWithPrivateUrls(String content) {
        if (content == null || content.isEmpty()) {
            return content;
        }
        try {
            // 匹配域名后的路径部分，支持各种文件名和查询参数
            // 例如: domain/path/to/image.jpg 或 domain/path/to/image.jpg?v=123
            String regex = Pattern.quote(DOMAIN) + "/([^\"'\\s]+)";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(content);
            StringBuffer result = new StringBuffer();
            while (matcher.find()) {
                String fullPath = matcher.group(1); // 获取完整的文件路径
                // 构建完整的原始URL
                String originalUrl = DOMAIN + "/" + fullPath;
                // 生成私有访问链接
                String privateUrl = generatePrivateUrl(originalUrl);
                // 替换URL，注意转义特殊字符
                matcher.appendReplacement(result, Matcher.quoteReplacement(privateUrl));
            }
            matcher.appendTail(result);

            return result.toString();
        } catch (Exception e) {
           // log.error("处理富文本URL失败: content={}", content, e);
            return content; // 处理失败时返回原内容
        }
    }




    private String generatePrivateUrl(String url) {
        // 如果url为空则直接返回
        if (url == null || url.isEmpty()) {
            return url;
        }

        String processedUrl = url;
        // 如果是以/开头的相对路径,添加域名
        if (url.startsWith("/")) {
            processedUrl = DOMAIN + url; // 这里的DOMAIN需要定义,比如 "https://cdn.example.com"
        }

        // 验证是否是合法的URL格式
        try {
            new URL(processedUrl);
            // 是合法URL,进行七牛云私有链接处理
            return auth.privateDownloadUrl(processedUrl, expireSeconds);
        } catch (MalformedURLException e) {
            // 不是合法URL格式,直接返回原字符串
            return url;
        }
    }



}
*/
